perm filename SYNTAX.PUB[206,JMC] blob sn#525080 filedate 1980-07-23 generic text, type T, neo UTF8
	It is often more convenient to describe certain kinds of
computation with symbolic expressions by "syntax transformations"
than by recursive LISP functions.  For example, consider the
simplification of expressions in a binary  PLUS  and  TIMES  where
the number  0  is to be eliminated from sums, the number  1  is to
be eliminated from products, products containing  0  are to be
replaced by  0, and sums and products of one element are to be
replaced by that element.
This may be accomplished by the function  simplifya  defined by

.begin nofill
	simplifya e ← qif qat e qthen e
			qelse α{simplifya qad e,simplifya qadd eα}
			[λw z. qif qa e qeq $PLUS qthen
				[qif w = 0 qthen z
				qelse qif z = 0 qthen w
				qelse <$PLUS w z>]
				qelse qif w = 0 ∨ z = 0 qthen 0
				qelse qif w = 1 qthen z
				qelse qif z = 1 qthen w
				qelse <$TIMES w z>.
.end